let navsecond = document.querySelector('.nav-second-body')
ajax({
  method: "get",
  url: "stage-api/website/getProductMenuInfo",
  success: function(res){
    console.log(res)
    for (let i = 0; i < res.data.length; i++) {
      if (i == 4) {
        continue;
      }else if(i == 6){
        continue;
      }else{
         navsecond.innerHTML += `<li class="nav-second-item" onclick="detail('${res.data[i].productId}')">
                                <div class="navsec-bod">
                                  <img src="${res.data[i].menuIcon.split("?")[0]}">
                                  <div>${res.data[i].productName}</div>
                                </div>
                              </li>`
      }
    }
  }
})

function detail(productId) {
      location.href = `product.html?productId=${productId}`
    }

function News(newsType){
  location.href = `newscenter.html?newsType=${newsType}`
}

let newhref = location.href.split("=")[1]
let bannertitle = document.querySelector('.banner-title')
let bannertext = document.querySelector('.banner-text')
let detailtitle = document.querySelector('.detail-title-name')
console.log(newhref)
if(newhref == 1){
  bannertitle.innerText = "公司动态"
  bannertext.innerText = "公司动态"
  detailtitle.innerText = "公司动态"
}else{
  bannertitle.innerText = "行业动态"
  bannertext.innerText = "行业动态"
  detailtitle.innerText = "行业动态"
}

let newbody = document.querySelector('.body-left .newsbody')
ajax({
  method: "get",
  url: "stage-api/website/getNewsList",
  params: {
    pageNum: 1,
    pageSize: 3,
    newsType: newhref,
  },
  success: function(res){
    for(let i = 0; i < res.rows.length; i++){
      newbody.innerHTML += `<li class="item-warp" onclick=newsmore('${res.rows[i].newsId}')>
                              <div class="item">
                                <div class="item-img">
                                  <img src="${res.rows[i].newsPic}">
                                </div>
                                <div class="item-text">
                                  <div class="title">${res.rows[i].newsName}</div>
                                  <div class="content">${res.rows[i].remark}</div>
                                  <div class="time">${res.rows[i].createTime.split(" ")[0]}</div>
                                </div>
                              </div>
                            </li>`
    }
  }
})

function newsmore(newsId) {
  location.href = `newsmore${newhref}.html?newsId=${newsId}`
}

let number = document.querySelectorAll('.pagenumber')
number[1].onclick = function(){
  number[0].className = "pagenumber"
  number[2].className = "pagenumber"
  this.className = "pagenumber active"
  // $(this).addClass('.active').siblings().removeClass('active')
  $(".page3").css("display","none")
  $(".page1").css("display","none")
  $(".page2").css("display","block")
  $(".nextpage").attr("disabled", true)
  $(".lestpage").attr("disabled", false)
}
number[0].onclick = function(){
  number[1].className = "pagenumber"
  number[2].className = "pagenumber"
  this.className = "pagenumber active"
  // $(this).addClass('.active').siblings().removeClass('active')
  $(".page2").css("display","none")
  $(".page1").css("display","block")
  $(".page3").css("display","none")
  $(".nextpage").attr("disabled", false)
  $(".lestpage").attr("disabled", true)
}
number[2].onclick = function(){
  number[1].className = "pagenumber"
  number[0].className = "pagenumber"
  this.className = "pagenumber active"
  // $(this).addClass('.active').siblings().removeClass('active')
  $(".page2").css("display","none")
  $(".page3").css("display","block")
  $(".page1").css("display","none")
  $(".nextpage").attr("disabled", false)
  $(".lestpage").attr("disabled", true)
}
let act = document.querySelector('.action')
$(".nextpage").click(function() {
  act.nextElementSibling.onclick()
})
$(".lestpage").click(function() {
  act.previousElementSibling.onclick()
})

let rightitem = document.querySelector(".body-right-text .text-body")
ajax({
  method: "get",
  url: "stage-api/website/getProductMenuInfo",
  success: function(res){
    for (let i = 0; i < res.data.length; i++) {
      if (i <= 4) {
        rightitem.innerHTML += `<li class="item-wrap" onclick="detail('${res.data[i].productId}')">
                                  <div class="item">
                                    <img src="${res.data[i].logoPhotoAddress.split("?")[0]}">
                                    <div class="item-right">
                                      <div class="item-title">${res.data[i].productName}</div>
                                      <div class="item-text">${res.data[i].productName}</div>
                                    </div>
                                  </div>
                                </li>`
      }else{
        break;
      }
    }
  }
})